import QtQuick 2.0
import "Widgets" as Widgets


Rectangle {
    id: root
    width: 800
    height: 800

    property alias interfaceAddress: interfaceLineEdit.text
    property alias multicastGroup: multicastLineEdit.text
    property alias port: portSpinBox.value
    property alias nodeName: nodeNameLineEdit.text
    property string status: "IDLE"

    property alias inPackets: statistic.inPackets
    property alias inBytes: statistic.inBytes
    property alias outPackets: statistic.outPackets
    property alias outBytes: statistic.outBytes

    signal setProperty(string url)
    signal propertyChange(string url)
    signal execFunction(string url)



    Background {
        anchors.fill: parent
        state: "dust"
    }

    Rectangle { // top panel
        id: topPanel
        anchors.left: parent.left; anchors.right: parent.right; height: 40
        color: "black"; opacity: 0.5
    }

    Widgets.ToolButton {
        icon: "img/call.png"
        anchors.right: parent.right
        width: 40
        height: 40
    }

    Text { // logo text
        id: logo
        anchors.verticalCenter: topPanel.verticalCenter; x: 20
        text: "Sh network debugger"
        color: "#70ccff"; font.family: "Orbitron"; font.pointSize: 16
    }

    Statistic { // recieved / send
        id: statistic
        anchors.left: logo.right; anchors.leftMargin: 15
        anchors.verticalCenter: topPanel.verticalCenter
        height: topPanel.height
    }

    Widgets.Box { // packets in / out
        id: packetsBox
        anchors.top: topPanel.bottom; anchors.right: parent.right
        anchors.bottom: toolsBox.top; anchors.margins: 20
        anchors.left: settingsBox.right

        Widgets.Label {
            pointSize: 14
            text: "Live capture"
            x: 25; y: 5
        }

        Item {
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 25; anchors.leftMargin: 10; anchors.rightMargin: 10
            height: parent.height - 60
            clip: true
            LogViewer {
                id: packetsList
                objectName: "packets"
                anchors.fill: parent
                maxItems: 200
            }
        }
    }

    Widgets.Box { // settings
        id: settingsBox
        Widgets.Label {
            pointSize: 14
            text: "Network settings"
            x: 25; y: 5
        }

        anchors.top: topPanel.bottom; anchors.left: parent.left
        height: 240; anchors.margins: 20
        width: 350

        Grid {
            id: settingsGrid
            y: 40
            anchors.horizontalCenter: parent.horizontalCenter
            rows: 4
            columns: 2
            spacing: 7
            Widgets.Label { text: "Interface" }
            Widgets.DarkLineEdit {
                id: interfaceLineEdit
                KeyNavigation.tab: multicastLineEdit
                text: "192.168.7.7"
            }
            Widgets.Label { text: "Multicast" }
            Widgets.DarkLineEdit {
                id: multicastLineEdit
                KeyNavigation.tab: interfaceLineEdit
                text: "239.1.1.1"
            }
            Widgets.Label { text: "Port" }
            Widgets.SpinBox {
                id: portSpinBox
                min: 1
                max: 100000
                value: 45454
            }
            Widgets.Label { text: "Node name" }
            Widgets.DarkLineEdit {
                id: nodeNameLineEdit
                KeyNavigation.tab: interfaceLineEdit
                text: "debugger"
            }
        }
        Widgets.Button {
            id: joinButton
            objectName: "joinButton"
            text: "Join"
            anchors.top: settingsGrid.bottom
            anchors.right: settingsGrid.right
            anchors.topMargin: 15
        }
        Widgets.Label {
            text: "Status: " + root.status;
            anchors.verticalCenter: joinButton.verticalCenter
            anchors.left: settingsGrid.left
        }
    }

    Widgets.Box { // tools
        id: toolsBox
        Widgets.Label {
            pointSize: 14
            text: "Tools"
            x: 25; y: 5
        }

        anchors.bottom: parent.bottom; anchors.left: settingsBox.right
        anchors.right: parent.right
        height: 190; anchors.margins: 20
        width: parent.width

        Grid {
            id: toolsGrid
            y: 35
            anchors.left: parent.left; anchors.right: parent.right
            anchors.leftMargin: 20; anchors.rightMargin: 20
            rows: 4
            columns: 2
            spacing: 7
            Widgets.Label { text: "Property set" }
            Widgets.DarkLineEdit {
                id: propertySetLineEdit
                width: parent.width - 130
                onReturnPressed: root.setProperty(text)
            }
            Widgets.Label { text: "Property change" }
            Widgets.DarkLineEdit {
                id: propertyChangeLineEdit
                width: parent.width - 130
                onReturnPressed: root.propertyChange(text)
            }
            Widgets.Label { text: "Exec function" }
            Widgets.DarkLineEdit {
                id: execFunctionLineEdit
                width: parent.width - 130
                onReturnPressed: root.execFunction(text)
            }
            Widgets.Label { text: "Throw event" }
            Widgets.DarkLineEdit {
                id: eventLineEdit
                width: parent.width - 130
            }

        }

    }

    Widgets.Box { // console out
        id: debugBox
        Widgets.Label {
            pointSize: 14
            text: "Console"
            x: 25; y: 5
        }

        anchors.left: parent.left;
        anchors.top: settingsBox.bottom
        anchors.bottom: parent.bottom
        height: 130; anchors.margins: 20
        width: 350
    }

}
